package com.sphd.education.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sphd.education.R;
import com.sphd.education.info.LessonInfo;
import com.sphd.education.modle.EducationUrl;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by hu on 2016/1/12.
 */
public class MyAddNameLessonAdapter extends BaseAdapter {
    Context context;
    List<LessonInfo> infos;
    private DisplayImageOptions displayImageOptions;

    public MyAddNameLessonAdapter(Context context, List<LessonInfo> infos) {
        this.context = context;
        this.infos = infos;
        displayImageOptions = EducationUrl.setImg();
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_my_add_lesson, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.lessonBegintime.setText(" 开学时间" + infos.get(position).getBeginTime());
        viewHolder.lessonSchoolName.setText(infos.get(position).getSchoolName().toString());
        viewHolder.lessonSchoolPhone.setText(infos.get(position).getPhone().toString());
        viewHolder.lessonName.setText(infos.get(position).getName().toString());
        ImageLoader.getInstance().displayImage(EducationUrl.HttpTitle + infos.get(position).getImage(),
                viewHolder.lessonSchoolImg, displayImageOptions);
        viewHolder.lessonIntroduction.setText(infos.get(position).getDescription().toString());
        viewHolder.lessonMoney.setText("￥" + infos.get(position).getRealTuition());
        if (infos.get(position).getTuitionStatus()==0){
            viewHolder.moeyType.setImageResource(R.mipmap.yibaoming);
        }else if (infos.get(position).getTuitionStatus()==1){
            viewHolder.moeyType.setImageResource(R.mipmap.baomingchenggong);
        }else if (infos.get(position).getTuitionStatus()==2){
            viewHolder.moeyType.setImageResource(R.mipmap.bujiaofei);
        }
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.lesson_begintime)
        TextView lessonBegintime;
        @Bind(R.id.lesson_school_name)
        TextView lessonSchoolName;
        @Bind(R.id.lesson_school_phone)
        TextView lessonSchoolPhone;
        @Bind(R.id.lesson_school_img)
        ImageView lessonSchoolImg;
        @Bind(R.id.lesson_name)
        TextView lessonName;
        @Bind(R.id.lesson_introduction)
        TextView lessonIntroduction;
        @Bind(R.id.lesson_money)
        TextView lessonMoney;
        @Bind(R.id.money_type)
        ImageView moeyType;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
